function [perm_a,inv_a,perm_b,inv_b] = gen_perm_matrix(pilot_a,pilot_b,n_subc)


perm_a = zeros(n_subc,1);
perm_b = zeros(n_subc,1);


search_window = [1:1:n_subc];
pilot_loc_a = find(pilot_a);
perm_a(pilot_loc_a) = pilot_loc_a;
search_window(pilot_loc_a) = [];

for i = 1:n_subc
    if(~pilot_a(i));
        rand_int_a = randi([1,length(search_window)],1);
            
        perm_a(i) = search_window(rand_int_a);
        search_window(rand_int_a) = [];
    end
   % end
   
end

[sorteda,inv_a]  = sort(perm_a);


search_window = [1:1:n_subc];
pilot_loc_b = find(pilot_b);
perm_b(pilot_loc_b) = pilot_loc_b;
search_window(pilot_loc_b) = [];

for i = 1:n_subc
    if(~pilot_b(i))
        rand_int_b = randi([1,length(search_window)],1);
            
        perm_b(i) = search_window(rand_int_b);
        search_window(rand_int_b) = [];
    end
   % end
   
end

[sortedb,inv_b]  = sort(perm_b);
